import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  server: {
    port: 3000,
    open: true,
    proxy: {
      // 代理认证服务
      '/auth': {
        target: 'http://localhost:51800',
        changeOrigin: true,
        rewrite: (path) => path
      },
      // 代理管理端业务服务
      '/admin': {
        target: 'http://localhost:51800',
        changeOrigin: true,
        rewrite: (path) => path
      },
      // 代理图书服务（直接调用book-service）
      '/book': {
        target: 'http://localhost:51800',
        changeOrigin: true,
        rewrite: (path) => path
      },
      // 代理用户服务（直接调用user-service）
      '/user': {
        target: 'http://localhost:51800',
        changeOrigin: true,
        rewrite: (path) => path
      }
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/styles/variables.scss" as *;`,
        api: 'modern-compiler'
      }
    }
  }
})
